<?
    /**
    * @Web site : teoynougi.com
    * @version  : 1.0
    * @author   : Teoynougi
    */


class Text {

	public static function str_limit($text, $length){
        if(strlen($text) > $length)
            $text = substr($text, 0, $length). "...";
        return $text;
    }

    public static function excerpt_word( $text, $excerpt_length ) {
        $excerpt_more = ' ...';
        
        $words = explode(' ', $text, $excerpt_length + 1);
        if (count($words) > $excerpt_length) {
            array_pop($words);
            $text = implode(' ', $words);
            $text = $text . $excerpt_more;
        }
        return $text;
    }

	public static function excerpt($text, $excerpt_length = 0) {

		if($excerpt_length == 0){

			$tmp = explode('<!-- pagebreak -->', $text);
			$text = $tmp[0];
			$text = str_replace(']]>', ']]&gt;', $text);
			$text = strip_tags($text);

			return $text;
		}

		$text = str_replace(']]>', ']]&gt;', $text);
		$text = strip_tags($text);

		$excerpt_more = ' ...';

		$words = explode(' ', $text);

		$result = "";
		$_result = "";

		foreach($words as $k => $v){
			$result .= $v." ";

			if( strlen($result) > $excerpt_length ){
				if(strlen($result) > $excerpt_length + 15) {

					$_result = substr($_result, 0, -1);
					return $_result . $excerpt_more;
				}else{

					$result = substr($result, 0, -1);
					return $result . $excerpt_more;
				}
			}

			$_result .= $v." ";
		}

		$result = substr($result, 0, -1);

		return $result;
	}

    public static function strip_html( $text ) {
        $text = str_replace(']]>', ']]&gt;', $text);
        $text = strip_tags($text);

        return $text;
    }

    
}

?>